package com.ss.android.article.base.feature.detail2.widget;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import com.bytedance.common.utility.UIUtils;
import com.ss.android.article.base.app.AppData;
import com.ss.android.article.base.ui.LoadingFlashView;
import com.ss.android.article.base.ui.NoDataViewFactory$ImgType;
import com.ss.android.article.base.ui.NoNetView;
import com.ss.android.article.base.ui.aa;
import com.ss.android.article.base.ui.ab;
import com.ss.android.article.base.ui.ac;
import com.ss.android.article.base.ui.ad;
import com.ss.android.article.browser.R;

public class DetailErrorView extends FrameLayout {
    public NoNetView mNoNetView;
    View.OnClickListener mOnRetryClickListener;
    private LoadingFlashView mLoadingFlashView;
    private View.OnClickListener d = new View.OnClickListener() {
        public final void onClick(View arg2) {
            if (DetailErrorView.this.mOnRetryClickListener != null) {
                DetailErrorView.this.mOnRetryClickListener.onClick(arg2);
            }
        }
    };

    public DetailErrorView(Context arg2) {
        super(arg2);
        this.init();
    }

    public DetailErrorView(Context arg2, AttributeSet arg3) {
        super(arg2, arg3);
        this.init();
    }

    @TargetApi(value = 11)
    public DetailErrorView(Context context, AttributeSet attributeSet, int defaultStyle) {
        super(context, attributeSet, defaultStyle);
        this.init();
    }

    public final void showLoadingView() {
        if (this.getVisibility() != VISIBLE) {
            this.setVisibility(VISIBLE);
        }

        if (this.mLoadingFlashView.getVisibility() != VISIBLE) {
            this.mLoadingFlashView.setVisibility(VISIBLE);
            AppData.getInstance();
            if (AppData.isNightMode()) {
                new PorterDuffColorFilter(mLoadingFlashView.getResources().getColor(com.ss.android.article.browser.R.color.ny), PorterDuff.Mode.SRC_ATOP);
            }
        }

        if (this.mNoNetView.getVisibility() == VISIBLE) {
            this.mNoNetView.setVisibility(GONE);
        }

        this.mLoadingFlashView.start();
    }

    public final void showNoDataUI(boolean isGallery) {
        if (this.getVisibility() != VISIBLE) {
            this.setVisibility(VISIBLE);
        }

        if (this.mLoadingFlashView.getVisibility() == VISIBLE) {
            this.mLoadingFlashView.setVisibility(GONE);
        }

        if (this.mNoNetView.getVisibility() != VISIBLE) {
            this.mNoNetView.setVisibility(VISIBLE);
            if (isGallery) {
                ColorStateList colorStateList = this.getResources().getColorStateList(com.ss.android.article.browser.R.color.z2);
                try {
                    mNoNetView.mBtnNoDataAction.setTextColor(colorStateList);
                    UIUtils.setMaxLines(mNoNetView.mBtnNoDataAction, R.drawable.cb);
                } catch (Exception exception) {
                }
            } else {
                this.mNoNetView.initNoDataActionBtn();
            }
        }

        this.mLoadingFlashView.stop();
    }

    public final void hideSelf() {
        this.setVisibility(GONE);
        this.mLoadingFlashView.stop();
    }

    private void init() {
        LayoutInflater.from(this.getContext()).inflate(com.ss.android.article.browser.R.layout.view_detail_error, ((ViewGroup) this));
        this.mLoadingFlashView = this.findViewById(com.ss.android.article.browser.R.id.loading_flash_view);
        this.mNoNetView = android.support.design.a.a(this.getContext(),
                this,
                ac.a(NoDataViewFactory$ImgType.NOT_NETWORK),
                ad.a(this.getContext().getString(com.ss.android.article.browser.R.string.not_network_tip)),
                ab.a(new aa(this.getContext().getString(com.ss.android.article.browser.R.string.label_retry), this.d)));
        ViewGroup.LayoutParams layoutParams = this.mNoNetView.getLayoutParams();
        layoutParams.width = -2;
        layoutParams.height = -2;
        ((FrameLayout.LayoutParams) layoutParams).gravity = 17;
    }

    public boolean onTouchEvent(MotionEvent event) {
        super.onTouchEvent(event);
        return true;
    }

    public void setOnRetryClickListener(View.OnClickListener onRetryClickListener) {
        this.mOnRetryClickListener = onRetryClickListener;
    }
}

